package com.jkc.xh.fragments;

import android.content.ClipboardManager;
import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.jkc.xh.R;
import com.jkc.xh.fragments.core.BaseFragment;
import com.jkc.xh.manager.UserManager;
import com.jkc.xh.network.RestCallBack;
import com.jkc.xh.network.models.InviteFriendResponse;
import com.jkc.xh.network.models.RestError;
import com.jkc.xh.views.widget.NavBar;
import com.jkc.xh.views.widget.ToastUtil;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.ViewById;

/**
 * 我要提现
 * Created by zhangbreeze on 15/11/21.
 */
@EFragment(R.layout.fragment_invite_friend)
public class InviteFriendFragment extends BaseFragment {

    @ViewById(R.id.nav_bar)
    NavBar nav_bar;
    @ViewById(R.id.shareContent)
    EditText shareContent;
    @ViewById(R.id.inviteTitle)
    TextView inviteTitle;

    private ClipboardManager myClipboard;

    @AfterViews
    public void initData() {
        nav_bar.setOnMenuClickListener(new NavBar.OnMenuClickListener() {
            @Override
            public void onLeftMenuClick(View view) {
                finishFragment();
            }
        });
        myClipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);

        UserManager.doInviteFriend(new RestCallBack<InviteFriendResponse>() {
            @Override
            public void success(InviteFriendResponse response) {
                shareContent.setText(response.cont + response.link);
                inviteTitle.setText(response.title);
            }

            @Override
            public void failure(RestError error) {
                ToastUtil.showToastShort(error.msg);
            }
        });
    }


    @Click(R.id.btnSave)
    void doInvite() {

        String content = shareContent.getText().toString();
        if (TextUtils.isEmpty(content)) {
            return;
        }
        myClipboard.setText(content);
        ToastUtil.showToastShort("已经复制到黏贴板!");
    }
}
